package com.monkeygroup.mygoplus.view.home.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.base.BaseActivity;
import com.monkeygroup.mygoplus.view.home.activity.rent.PublishedRentCarportAcitivity;
import com.monkeygroup.mygoplus.view.home.activity.sell.PublishedActivity;
import com.monkeygroup.mygoplus.view.home.activity.sell.PublishedCarportActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by cumt on 2017/5/27.
 */

public class PublishedThirdActivity extends BaseActivity implements View.OnClickListener {

    public static void gotoActivity(Activity activity,String propertytype, String type) {
        Intent intent = new Intent(activity,
                PublishedThirdActivity.class);

        intent.putExtra("type", type);
        intent.putExtra("propertytype", propertytype);


        activity.startActivity(intent);
    }

    private ListView publishList;
    private List<String> leftListItems;

    private PublishedThirdActivity.LeftAdapter adapter;

    private String type,propertytype;
    private ImageView imgBack;
    private TextView txtTitle;

    @Override
    public void onClick(View view) {

    }

    @Override
    public void setContentView() {
        setContentView(R.layout.published_second);
    }

    @Override
    public void initView() {

        publishList= (ListView)findViewById(R.id.publish_list);

        leftListItems = new ArrayList<String>();

        imgBack = (ImageView) findViewById(R.id.img_back);
        txtTitle = (TextView) findViewById(R.id.txt_title);


        adapter = new PublishedThirdActivity.LeftAdapter(PublishedThirdActivity.this);
        publishList.setAdapter(adapter);

        Intent intent = this.getIntent();
        Bundle bundle =  intent.getExtras();
        type = bundle.getString("type");
        propertytype= bundle.getString("propertytype");
        fillData(type);

    }

    @Override
    public void setListener() {

    }

    @Override
    public void doEvent() {

    }

    private void fillData(String type){
        txtTitle.setText("車位類型");
        //平面
        if("0".equals(type)){

            leftListItems.add("立體塔式");
            leftListItems.add("戶外廣場");
            leftListItems.add("室內地下");
            leftListItems.add("橋下");
            leftListItems.add("路邊");

        }
        //機械
        else if("1".equals(type)){

            leftListItems.add("立體塔式");
            leftListItems.add("戶外廣場");
            leftListItems.add("室內地下");
            leftListItems.add("橋下");
            leftListItems.add("路邊");


        }


        adapter.notifyDataSetChanged();

    }

    public class LeftAdapter extends BaseAdapter {


        private LayoutInflater mInflater;


        public LeftAdapter(Context context){
            this.mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getCount() {
            return leftListItems.size();
        }

        @Override
        public Object getItem(int position) {
            return leftListItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View myconvertView, ViewGroup parent) {

            View leftconvertView = mInflater.inflate(R.layout.published_second_item, null);
            final String obj = leftListItems.get(position);
            final TextView txtName = (TextView) leftconvertView
                    .findViewById(R.id.txt_publish_content);
            txtName.setText(obj);


            leftconvertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //出租
                    if("1".equals(propertytype)){
                        PublishedRentCarportAcitivity.gotoActivity(PublishedThirdActivity.this,type,""+position);
                    }
                    //出售
                    else if("2".equals(propertytype)){
                        PublishedCarportActivity.gotoActivity(PublishedThirdActivity.this,type,""+position);
                    }


                }
            });

            return leftconvertView;
        }



    }
}
